package com.lemil.forsquares.api.foursquare.util;

import java.util.Random;

import com.lemil.forsquares.api.foursquare.FoursquareApi.Location;

public class LocationUtils {

	public static final Random rnd = new Random(System.currentTimeMillis());

	public static Location randomNearLocation(Location location, double delta) {

		String geolat = getRandomValue(location.getGeolat(), delta);
		String geolong = getRandomValue(location.getGeolong(), delta);
		String geohacc = getRandomValue(location.getGeohacc(), delta);
		String geovacc = getRandomValue(location.getGeovacc(), delta);
		String geoalt = getRandomValue(location.getGeoalt(), delta);

		Location newloc = new Location(geolat, geolong, geohacc, geovacc, geoalt);
		
		return newloc;

	}

	private static String getRandomValue(String d0, double delta) {

		if (d0 != null) {
			double d1 = rnd.nextDouble();
			Double d2 = new Double(d0);
			double d3 = rnd.nextDouble();
			if (d3 > 5D) {
				d2 = d2 + (d1 * delta / 2) ;
			} else {
				d2 = d2 - (d1 * delta / 2) ;
			}
			//System.out.println( (d1 * delta / 2) );
			return d2.toString();
		} else {
			return null;
		}

	}

}
